package com.vhall.component.framework.common.exception;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.slf4j.MDC;

import java.io.Serializable;
import java.util.Date;

@Getter
@Setter
@Accessors(chain = true)
public class ExceptionResult implements Serializable {

    public ExceptionResult() {
        this.timestamp = new Date();
    }

    public ExceptionResult(String message, Integer code, String path) {
        this.msg = message;
        this.code = code;
        this.path = path;
        this.key = "failed";
        this.timestamp = new Date();
    }

    public ExceptionResult(String key, String message, Integer code, String path) {
        this.msg = message;
        this.code = code;
        this.key = key;
        this.path = path;
        this.timestamp = new Date();
    }


    /**
     * HttpStatus
     */
    private Integer code;

    /**
     * 语言包key
     */
    private String key;

    /**
     * 业务异常信息
     */
    private String msg;

    /**
     * 异常路径
     */
    private String path;

    /**
     * 异常时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    private Date timestamp;

    private String trace_id = MDC.get("traceId");

    private Object data;

    /**
     * 异常堆栈
     */

    @JsonIgnore
    @JSONField(serialize = false)
    private Throwable throwable;

    /**
     * 处理状态
     */
    private boolean success = false;


}
